#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>

#include <iostream>
#include <stdexcept>
#include <cstdlib>

const uint32_t WIDTH = 800;
const uint32_t HEIGHT = 600;

class HelloTriangleApplication
{
public:
    void run()
    {
        initWindow();
        initVulkan();
        mainLoop();
        cleanup();
    }

private:
    GLFWwindow *window;

    void initWindow()
    {
        glfwInit();
        // 告诉glfw不要使用后续调用来创建OPENGL上下文
        glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
        // 禁用resize
        glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
        // 初始化窗口
        window = glfwCreateWindow(WIDTH, HEIGHT, "Vulkan", nullptr, nullptr);
    }

    void initVulkan()
    {
    }

    void mainLoop()
    {
        // 一直运行直到窗口关闭或者发生错误
        while (!glfwWindowShouldClose(window))
        {
            // 处理窗口事件
            glfwPollEvents();
        }
    }

    void cleanup()
    {
        // 清理Vulkan资源
        //...
        // 销毁窗口
        glfwDestroyWindow(window);
        // 终止GLFW库
        glfwTerminate();
    }
};

int main()
{
    HelloTriangleApplication app;

    try
    {
        app.run();
    }
    catch (const std::exception &e)
    {
        std::cerr << e.what() << std::endl;
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}